﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Admin_ChiTietThue : System.Web.UI.Page
{
    ClassThueCD cctt = new ClassThueCD();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            if (Session["user"] == null)
                Response.Redirect("DangNhap.aspx");
            else
            {
                MultiView1.SetActiveView(View2);
                GridView1.DataSource = cctt.DSCTThueCD();
                GridView1.DataBind();
            }
        }
    }
    protected void btnThem_Click(object sender, EventArgs e)
    {
        MultiView1.SetActiveView(View1);
    }
    protected void btnLuu_Click(object sender, EventArgs e)
    {
        GridView1.DataSource = cctt.ThemCTThueCD(int.Parse(TextBox5.Text), int.Parse(TextBox1.Text), int.Parse(TextBox2.Text),int.Parse(TextBox3.Text), float.Parse(TextBox4.Text));
        GridView1.DataBind();
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
    }
    protected void btnHuy_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        TextBox4.Text = "";
        MultiView1.SetActiveView(View2);
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        GridView1.DataSource = cctt.DSCTThueCD();
        GridView1.DataBind();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int mthue = int.Parse(GridView1.Rows[e.RowIndex].Cells[1].Text);

        TextBox txtmp = (TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0];
        string mp = txtmp.Text;

        TextBox txtsl = (TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0];
        string sl = txtsl.Text;

        TextBox txtslg = (TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0];
        string slg = txtslg.Text;

        TextBox txtslt = (TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0];
        string slt = txtslt.Text;

        TextBox txtgt = (TextBox)GridView1.Rows[e.RowIndex].Cells[6].Controls[0];
        string gt = txtgt.Text;

        cctt.SuaCTCD(mthue,int.Parse(mp), int.Parse(sl),int.Parse( slg),int.Parse( slt),float.Parse( gt));

        GridView1.EditIndex = -1;
        GridView1.DataSource = cctt.DSCTThueCD();
        GridView1.DataBind();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        GridView1.DataSource = cctt.DSCTThueCD();
        GridView1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                CheckBox chb = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
                if (chb.Checked == true)
                {
                    int ma = Convert.ToInt32(GridView1.Rows[i].Cells[1].Text);
                    cctt.XoaCTThueCD(ma);
                }
            }
        }
        catch (Exception ex)
        {
            Label1.Text = ex.Message;

        }
        GridView1.DataSource = cctt.DSCTThueCD();
        GridView1.DataBind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataSource = cctt.DSCTThueCD();
        GridView1.DataBind();
    }
}
